package com.qdlc.p2p.biz.modelbuidler;

import com.qdlc.p2p.common.constant.Summary;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.common.util.OrderNoUtils;
import com.qdlc.p2p.dal.dto.BorrowTender;
import com.qdlc.p2p.dal.dto.Tpp;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.TppTradeLogModel;
import com.qdlc.p2p.dal.util.UserUtils;

public class TppBuilder {

    private Tpp tpp;
    Summary summaryServiceType;
    User user;
    User toUser;
    double money;

    /** 关联订单号 */
    String associateOrderId;

    BorrowTender tender;

    private TppBuilder() {
        tpp = new Tpp();
    }

    public static TppBuilder newBuilder() {
        return new TppBuilder();
    }


    public Summary getSummaryServiceType() {
        return summaryServiceType;
    }

    public TppBuilder setSummaryServiceType(Summary summaryServiceType) {
        this.summaryServiceType = summaryServiceType;
        return this;
    }

    public User getUser() {
        return user;
    }

    public TppBuilder setUser(User user) {
        this.user = user;
        return this;
    }

    public User getToUser() {
        return toUser;
    }

    public TppBuilder setToUser(User toUser) {
        this.toUser = toUser;
        return this;
    }

    public double getMoney() {
        return money;
    }

    public TppBuilder setMoney(double money) {
        this.money = money;
        return this;
    }

    public BorrowTender getTender() {
        return tender;
    }

    public TppBuilder setTender(BorrowTender tender) {
        this.tender = tender;
        return this;
    }

    public String getAssociateOrderId() {
        return associateOrderId;
    }

    public TppBuilder setAssociateOrderId(String associateOrderId) {
        this.associateOrderId = associateOrderId;
        return this;
    }

    public Tpp build() {
        tpp.setServiceType(TppTradeLogModel.getTppServiceType(summaryServiceType.getSummaryType()));
        tpp.setTppType(summaryServiceType.getSummaryType());
        if (user != null) {
            tpp.setTppUserCustId(UserUtils.getUserTppCustId(user.getUserId()));
        }
        if (toUser != null) {
            tpp.setToTppUserCustId(UserUtils.getUserTppCustId(toUser.getUserId()));
        }
        tpp.setMoney(money);
        tpp.setTender(tender);
        tpp.setOrderId(OrderNoUtils.getSerialNumber());
        tpp.setOrderDate(DateUtil.dateStr7(DateUtil.getNow()));
        tpp.setAddTime(DateUtil.getNow());

        return tpp;
    }
}
